package jianzhiOfferII;

import java.util.Arrays;

//剑指 Offer II 014. 字符串中的变位词
public class Num014_checkInclusion {
    public boolean checkInclusion(String s1, String s2) {
        int []a1 = new int[26];
        int []a2 = new int[26];
        int m = s1.length() , n = s2.length();
        for (int i = 0; i < m; i++) {
            a1[s1.charAt(i) - 'a']++;
        }
        for (int l = 0 , r = 0; r < n; r++) {
            a2[s2.charAt(r) - 'a']++;
            if (r - l + 1 > m){
                a2[s2.charAt(l++) - 'a']--;
            }
            if (isInclusion(a1 , a2))return true;
        }
        return false;

    }
    public boolean isInclusion(int []a1, int []a2) {
        return Arrays.equals(a1 , a2);
    }
}
